package model;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

public class Sprite implements Collisionable {

	SpriteType st;
	int[] position = {0,0};
	
	public Sprite(SpriteType st){
		this.st = st;
	}
	public Sprite(ImageIcon icon, SimpleCollisionMap collMap){
		this.st=new SpriteType(icon,collMap);
	}
	public Sprite(String iconUrl, String collisionMapUrl) throws IOException{
		BufferedImage img = ImageIO.read( new File(collisionMapUrl) );
		this.st=new SpriteType(new ImageIcon(iconUrl),new SimpleCollisionMap(img));
	}
	public Sprite(String imageUrl) throws IOException{
		this(imageUrl,imageUrl);
	}
	
	public ImageIcon getImage(){
		return st.getImg();
	}
	public ImageIcon getCollisionMapImage(){
		return st.getCollisionMapImage();
	}
	public void setImage(ImageIcon img){
		st.setImg(img);
	}
	public int[] getPosition(){
		return position;
	}
	public void setPosition(int[] position){
		if(position.length==2){
			this.position=position;
		}
	}
	public void setPosition(int x,int y){
		int[] pos = {x,y};
		setPosition(pos);
	}
	public void move(int[] decal){
		if(decal.length==2){
			this.position[0]+=decal[0];
			this.position[1]+=decal[1];
		}
		
	}
	public void move(int x,int y){
		this.position[0]+=x;
		this.position[1]+=y;
	}
	public SimpleCollisionMap getCollisionMap(){
		return st.getCollisionMap();
	}
	public void setCollisionMap(SimpleCollisionMap collMap){
		st.setCollisionMap(collMap);
	}
}
